package com.eqdd.yiqidian.http;


import com.eqdd.yiqidian.kotlin.KotlinBaseActivity;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.Request;

import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

/**
 * Created by lvzhihao on 17-7-4.
 */

public abstract class HttpCallBack<T> extends JsonCallBack<T> {
    private KotlinBaseActivity activity;

    public HttpCallBack(KotlinBaseActivity activity) {
        super();
        this.activity = activity;
    }

    @Override
    public void onStart(Request<T, ? extends Request> request) {
        super.onStart(request);
        activity.showLoading();
    }

    @Override
    public void onFinish() {
        super.onFinish();
        activity.hideLoading();

    }

    @Override
    public void onError(Response<T> response) {
        super.onError(response);
        if (response.getException() instanceof SocketTimeoutException) {
            ToastUtil.showShort("网络连接超时");
        } else if (response.getException() instanceof UnknownHostException) {
            ToastUtil.showShort("网络不可达");
        }
    }
}
